package com.bsoft.controller;

import com.bsoft.productor.Demo06Producer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.CountDownLatch;

@Slf4j
@RestController
public class Demo06Controller {
    @Autowired
    private Demo06Producer demo06Producer;
    @GetMapping("testSynSend01")
    public void  testSynSend01() throws InterruptedException {
        //发送三条记录
        this.testSynSend(3);
        
    }
    @GetMapping("testSynSend02")
    public void  testSynSend02() throws InterruptedException {
        //发
        this.testSynSend(10000);

    }


    private void testSynSend(int n) throws InterruptedException {
        for (int i=0; i<n ;i++){
            //同步发送消息

            int id = (int) (System.currentTimeMillis() / 1000);
            demo06Producer.synSend(id);
            log.info("[testSyncSendMore][发送编号：[{}] 发送成功]", id);
        }
        //阻塞等待 保证消费
        new CountDownLatch(1).await();
    }
}
